package com.xxj.fflink.menu;

import android.content.Context;
import android.view.SurfaceHolder;

public abstract class MyGameView extends MyBaseView implements Runnable {

	protected boolean isRunning = false;

	private int refreshTime = 100 * 1000;

	public MyGameView(Context context) {
		this(context, 50);
	}

	public MyGameView(Context context, int refreshTime) {
		super(context);
		this.refreshTime = refreshTime;
		// start
		isRunning = true;
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		new Thread(this).start();
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		isRunning = false;
	}

	@Override
	public void run() {
		System.out.println(" *** isRunning:" + isRunning);
		while (isRunning) {
			synchronized (holder) {
				this.draw();
			}
			try {
				Thread.sleep(refreshTime);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
